package com.wltt.product.ahuthr.service;

import com.wltt.product.ahuthr.config.exception.BusinessException;
import com.wltt.product.ahuthr.mapper.SystemLevelSalaryMapper;
import com.wltt.product.ahuthr.model.ResultData;
import com.wltt.product.ahuthr.model.po.SystemLevelSalaryPO;
import com.wltt.product.ahuthr.model.vo.QuerySystemLevelByTypeReq;
import com.wltt.product.ahuthr.model.vo.QuerySystemLevelByTypeRsp;
import com.wltt.product.ahuthr.model.vo.QuerySystemPostByTypeRsp;
import com.wltt.product.ahuthr.service.base.BaseServiceImpl;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * @ClassName: SystemLevelSalaryServiceImpl
 * @Description: 逻辑服务类<br />
 * 不做业务校验，参数校验统一放到前置的Service中
 * @Date: 2024-05-30 14:34:21
 * @Author yanggl
 */
@Service(value = "systemLevelSalaryService")
public class SystemLevelSalaryServiceImpl extends BaseServiceImpl<SystemLevelSalaryPO, Long> implements SystemLevelSalaryService {

    private SystemLevelSalaryMapper systemLevelSalaryMapper;

    //构造方法
    public SystemLevelSalaryServiceImpl(SystemLevelSalaryMapper systemLevelSalaryMapper) {
        super(systemLevelSalaryMapper);
        this.systemLevelSalaryMapper = systemLevelSalaryMapper;
    }


    /**
     * 查询薪级
     *
     * @param querySystemPostByTypeReq
     * @return
     */
    @Override
    public ResultData querySystemLevelByType(QuerySystemLevelByTypeReq querySystemPostByTypeReq) {
        if (null == querySystemPostByTypeReq.getPostTypeId()) {
            throw new BusinessException("未指定岗位类别", HttpStatus.BAD_REQUEST);
        }
        List<SystemLevelSalaryPO> pos = systemLevelSalaryMapper.queryByPostTypeId(querySystemPostByTypeReq.getPostTypeId());
        List<QuerySystemLevelByTypeRsp> rsps = Optional.ofNullable(pos).orElse(new ArrayList<>())
                .stream().map(po -> {
                    QuerySystemLevelByTypeRsp bo = new QuerySystemLevelByTypeRsp();
                    bo.setId(po.getId());
                    bo.setLevelRank(po.getLevelRank());
                    return bo;
                }).toList();
        return ResultData.success(rsps);
    }
}